package com.kehutong.applet.admin;

import com.kehutong.common.util.Token;
import com.kehutong.applet.entity.AdvertPositionEntity;
import com.kehutong.applet.service.AdvertPositionService;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

/**
 * @program: kht
 * @description: 产品位置控制类
 * @author: joneron
 * @create: 2021/5/21
 **/
@MvcAction
@ReqMapping("/admin/crm/applet/position")
public class AdvertPositionController {

    @Inject
    AdvertPositionService advertPositionService;

    @ReqMapping("/list")
    @HasPermission("crm:applet:position:view")
    public Object list(JSONObject jsonObject) {
        return advertPositionService.findList(jsonObject);
    }

    @ReqMapping("/page")
    @HasPermission("crm:applet:position:view")
    public Object page(JSONObject jsonObject) {
        return advertPositionService.findPage(jsonObject);
    }

    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:applet:position:edit")
    @ReqMapping("/save")
    public Object save(AdvertPositionEntity advertEntity, Token token) {
        advertEntity.setCreateUserName(token.getUsername());
        return advertPositionService.save(advertEntity);
    }

    @Bean(copy=true)
    @HasPermission("crm:applet:position:edit")
    @ReqMapping("/update")
    public Object update(AdvertPositionEntity advertEntity) {

        return advertPositionService.update(advertEntity);
    }

    @HasPermission("crm:applet:position:edit")
    @ReqMapping("/delete")
    public Object delete(AdvertPositionEntity advertEntity) {

        return advertPositionService.deleteById(advertEntity.getId());
    }

    @ReqMapping("/setStatus")
    @HasPermission("crm:applet:position:edit")
    public Object setStatus(AdvertPositionEntity entity) {
        entity.setStatus(!entity.isStatus());
        advertPositionService.update(entity);
        return Result.success();
    }

    @ReqMapping("/get")
    public Object get(AdvertPositionEntity entity) {

        return Result.success(entity);
    }
}
